| Total Complexity | 7 |
| Total Lines | 64 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'; |
||
| 2 | |||
| 3 | @Entity() |
||
| 4 | export class Product { |
||
| 5 | @PrimaryGeneratedColumn('uuid') |
||
| 6 | private id: string; |
||
| 7 | |||
| 8 | @Column({ type: 'varchar', nullable: false }) |
||
| 9 | private title: string; |
||
| 10 | |||
| 11 | @Column({ type: 'varchar', nullable: true }) |
||
| 12 | private description: string; |
||
| 13 | |||
| 14 | @Column({ type: 'integer', nullable: false, default: 0 }) |
||
| 15 | private unitPrice: number; |
||
| 16 | |||
| 17 | @Column({ type: 'integer', nullable: false, default: 0 }) |
||
| 18 | private weight: number; |
||
| 19 | |||
| 20 | constructor( |
||
| 21 | title: string, |
||
| 22 | description: string, |
||
| 23 | unitPrice: number, |
||
| 24 | weight: number |
||
| 25 | ) { |
||
| 26 | this.title = title; |
||
| 27 | this.description = description; |
||
| 28 | this.unitPrice = unitPrice; |
||
| 29 | this.weight = weight; |
||
| 30 | } |
||
| 31 | |||
| 32 | public getId(): string { |
||
| 33 | return this.id; |
||
| 34 | } |
||
| 35 | |||
| 36 | public getTitle(): string { |
||
| 37 | return this.title; |
||
| 38 | } |
||
| 39 | |||
| 40 | public getDescription(): string { |
||
| 41 | return this.description; |
||
| 42 | } |
||
| 43 | |||
| 44 | public getUnitPrice(): number { |
||
| 45 | return this.unitPrice; |
||
| 46 | } |
||
| 47 | |||
| 48 | public getWeight(): number { |
||
| 49 | return this.weight; |
||
| 50 | } |
||
| 51 | |||
| 52 | public getPriceFromCents(): number { |
||
| 53 | return this.unitPrice / 100; |
||
| 54 | } |
||
| 55 | |||
| 56 | public update( |
||
| 57 | title: string, |
||
| 58 | description: string, |
||
| 59 | unitPrice: number, |
||
| 60 | weight: number |
||
| 61 | ): void { |
||
| 62 | this.title = title; |
||
| 63 | this.description = description; |
||
| 64 | this.unitPrice = unitPrice; |
||
| 65 | this.weight = weight; |
||
| 66 | } |
||
| 68 |